package de.mmbbs;

import java.io.IOException;
import java.io.InputStream;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Movie;
import android.os.Bundle;
import android.os.SystemClock;
import android.view.View;


public class AnimatedObject extends Basic2dObject{
	private InputStream stream;
	private Movie mMovie;
	private long mMovieStart;
	private static int posx = 90;
	private static int posy = 60;

	/** Called when the activity is first created. */
@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(new CustomGifView(this));		
	}
public int getPositionX(){
	return posx;
}
public int getPositionY(){
	return posy;
}
public void setPosition(int x, int y){
	posx = x;
	posy = y;
}

	class CustomGifView extends View {

		public CustomGifView(Context context) {
			super(context);
			try {
		           stream = getAssets().open("explode05.gif");
		        } catch (IOException e) {
		          e.printStackTrace();
		        }
			mMovie = Movie.decodeStream(stream);

		}
		@Override
		public void onDraw(Canvas canvas) {

			long now = SystemClock.uptimeMillis();
			
			if (mMovieStart == 0) { 
				mMovieStart = now;
			}
			if (mMovie != null) {
				int relTime = (int) ((now - mMovieStart));				
				mMovie.setTime(relTime);
				mMovie.draw(canvas, posx, posy);
				invalidate();
			}
		}

	}

}